package io.xxx.omni.oss.config

import org.springframework.boot.web.client.RestTemplateBuilder
import org.springframework.cloud.client.loadbalancer.LoadBalanced
import org.springframework.context.annotation.Bean
import org.springframework.context.annotation.Configuration
import org.springframework.http.client.JdkClientHttpRequestFactory
import org.springframework.web.client.RestTemplate
import java.util.function.Supplier

@Configuration
class WebConfig {

    @Bean
    fun restTemplate(builder: RestTemplateBuilder): RestTemplate {
        return builder
            .requestFactory(Supplier { JdkClientHttpRequestFactory() })
            .build()
    }

    @Bean
    @LoadBalanced
    fun lbRestTemplate(builder: RestTemplateBuilder): RestTemplate {
        return builder
            .requestFactory(Supplier { JdkClientHttpRequestFactory() })
            .build()
    }
}